<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="/WEB-INF/tags/functions.tld" %>
<%@ taglib prefix="t" uri="/WEB-INF/tags/tags.tld" %>

<div class="box">
	<h3 class="boxTitle">Tìm kiếm lớp học mở</h3>
	<form action="/student/registerClasses.html" method="GET">
		<table style="width: 100%">
			<tr>
				<td>Mã lớp</td>
				<td><input type="text" name="cId" id="cId" class="searchInput" value="${param.cId}" /></td>
				<td>Học phần</td>
				<td><input type="text" name="sId" id="sId" class="searchInput" value="${param.sId}" /></td>
			</tr>
			<tr>
				<td colspan="4"><input type="submit" value="Tìm kiếm" /></td>
			</tr>
		</table>
	</form>
</div>

<c:if test="${classes == null or empty classes}">
	<b>Không có lớp học nào được tìm thấy</b>
</c:if>
<c:if test="${classes != null and !empty classes}">
	<form action="/student/processRegisterClasses.html?cId=${param.cId}&sId=${param.sId}&p=${pageInfo.currentPage}" method="post">
		<table>
			<thead>
				<tr>
					<td class="th" style="width: 1em;"><input type="checkbox" name="selectAll" id="selectAll" /></td>
					<th class="th">STT</th>
					<th class="th">Mã lớp</th>	
					<th class="th">Tên lớp</th>
					<th class="th">Học phần</th>
					<th class="th">Giảng viên</th>	
				</tr>	
			</thead>
			<tbody>
			<c:forEach items="${classes}" var="c" varStatus="status">
				<tr>
					<td class="td" style="width: 1em;"><input type="checkbox" name="selectItem" value="${f:keyToString(c.classKey)}" /></td>
					<td class="td"><c:out value="${(pageInfo.currentPage - 1) * pageSize + status.count}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.classId}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.className}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.subject.subjectId}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.lecturer.lecturerName}" escapeXml="true" /></td>
				</tr>
			</c:forEach>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="6">
						<div class="pages">
							<t:paging pageInfo="${pageInfo}" link="/student/registerClasses.html" params="${params}"/>
						</div>
						<input type="submit" value="Đăng ký" id="selectGroup" disabled="disabled" style="margin-top: 1em;" />
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</c:if>